<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 16] NumberFormat</TITLE>
<META NAME="author" CONTENT="Mark Grand and Jonathan Knudsen">
<META NAME="date" CONTENT="Fri Aug  8 17:31:30 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java Fundamental Classes Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Fundamental Classes Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch16_13.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 16<br>The java.text Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch16_15.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>NumberFormat</H1>

<H2>Name</H2>

NumberFormat

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.99">Synopsis</A></h2>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Class Name:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.text.NumberFormat</tt>

<p>
<DT CLASS=varlistentry>Superclass:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.text.Format</tt>

<p>
<DT CLASS=varlistentry>Immediate Subclasses:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.text.ChoiceFormat</tt>, 
<tt CLASS=literal>java.text.DecimalFormat</tt>

<p>
<DT CLASS=varlistentry>Interfaces Implemented:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.lang.Cloneable</tt>

<p>
<DT CLASS=varlistentry>Availability:<br>
<DD>

<P CLASS=para>
New as of JDK 1.1 </DL>
</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.100">Description</A></h2>

<P CLASS=para>
The <tt CLASS=literal>NumberFormat</tt> class formats 
and parses numbers in a locale-specific manner. NumberFormat is an abstract 
class, but it provides factory methods that return useful instances of 
NumberFormat subclasses. These factory methods come in three groups: 

<P>
<UL CLASS=itemizedlist>
<li CLASS=listitem>The <tt CLASS=literal>getCurrencyInstance()</tt> 
methods return objects that format and parse currency values. 

<P>
<li CLASS=listitem>The <tt CLASS=literal>getNumberInstance()</tt> 
methods return objects that format and parse normal numbers. 

<P>
<li CLASS=listitem>The <tt CLASS=literal>getPercentInstance()</tt> 
methods return objects that format percentage values. 

<P>
</UL>
<P CLASS=para>
For example, to format a number as an Italian currency value, you can use 
this code: 

<DIV CLASS=screen>
<P>
<PRE>
double salary = 1234.56;
System.out.println
  (NumberFormat.getCurrencyInstance(Locale.ITALY).format(salary));
</PRE>
</DIV>

<P CLASS=para>
This produces the following output: 

<DIV CLASS=screen>
<P>
<PRE>
L 1.234,56
</PRE>
</DIV>

<P CLASS=para>
The <tt CLASS=literal>NumberFormat</tt> class defines 
two field constants that represent the integer and fractional fields in 
a formatted number. These field constants create <tt CLASS=literal>FieldPosition</tt> 
objects. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.101">Class Summary</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public abstract class java.text.NumberFormat extends java.text.Format
                      implements java.lang.Cloneable {
  // Constants
  public static final int FRACTION_FIELD;
  public static final int INTEGER_FIELD;
  // Class Methods
  public static Locale[] getAvailableLocales();
  public static final NumberFormat getCurrencyInstance();
  public static NumberFormat getCurrencyInstance(Locale inLocale);
  public static final NumberFormat getInstance();
  public static NumberFormat getInstance(Locale inLocale);
  public static final NumberFormat getNumberInstance();
  public static NumberFormat getNumberInstance(Locale inLocale);
  public static final NumberFormat getPercentInstance();
  public static NumberFormat getPercentInstance(Locale inLocale);
  // Instance Methods
  public Object clone();
  public boolean equals(Object obj); 
  public final String format(double number);
  public final String format(long number);
  public final StringBuffer format(Object number, StringBuffer toAppendTo,
                            FieldPosition pos); 
  public abstract StringBuffer format(double number, 
                               StringBuffer toAppendTo, FieldPosition pos);
  public abstract StringBuffer format(long number, StringBuffer toAppendTo, 
                               FieldPosition pos);
  public int getMaximumFractionDigits();
  public int getMaximumIntegerDigits();
  public int getMinimumFractionDigits();
  public int getMinimumIntegerDigits();
  public int hashCode();
  public boolean isGroupingUsed();
  public boolean isParseIntegerOnly();
  public Number parse(String text);
  public abstract Number parse(String text, ParsePosition parsePosition);
  public final Object parseObject(String source, 
                      ParsePosition parsePosition); 
  public void setGroupingUsed(boolean newValue);
  public void setMaximumFractionDigits(int newValue);
  public void setMaximumIntegerDigits(int newValue);
  public void setMinimumFractionDigits(int newValue);
  public void setMinimumIntegerDigits(int newValue);
  public void setParseIntegerOnly(boolean value);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.102">Constants</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.208">FRACTION_FIELD</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.237">public final static int FRACTION_FIELD</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
A field constant that represents the fractional 
part of the number. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.209">INTEGER_FIELD</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.238">public final static int INTEGER_FIELD</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
A field constant that represents the integer 
part of the number. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.103">Class Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.210">getAvailableLocales</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.239">public static Locale[] getAvailableLocales()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
An array of <tt CLASS=literal>Locale</tt> objects. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns an array of the <tt CLASS=literal>Locale</tt> 
objects for which this class can create <tt CLASS=literal>NumberFormat</tt> 
objects. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.211">getCurrencyInstance</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.240">public static final NumberFormat getCurrencyInstance()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>NumberFormat</tt> appropriate 
for the default <tt CLASS=literal>Locale</tt> that 
formats currency values. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses currency values in the default 
locale. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.241">public static NumberFormat getCurrencyInstance(Locale inLocale)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>inLocale</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Locale</tt> to use. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>NumberFormat</tt> appropriate 
for the given <tt CLASS=literal>Locale</tt> that formats 
currency values. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses currency values in the given 
locale. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.212">getInstance</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.242">public static final NumberFormat getInstance()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A default <tt CLASS=literal>NumberFormat</tt> appropriate 
for the default <tt CLASS=literal>Locale</tt>. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a default <tt CLASS=literal>NumberFormat</tt> 
that formats and parses values in the default locale. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.243">public static NumberFormat getInstance(Locale inLocale)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>inLocale</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Locale</tt> to use. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A default <tt CLASS=literal>NumberFormat</tt> appropriate 
for the given <tt CLASS=literal>Locale</tt>. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses values in the given locale. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.213">getNumberInstance</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.244">public static final NumberFormat getNumberInstance()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>NumberFormat</tt> appropriate 
for the default <tt CLASS=literal>Locale</tt> that 
formats normal numbers. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses number values in the default 
locale. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.245">public static NumberFormat getNumberInstance(Locale inLocale)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>inLocale</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Locale</tt> to use. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>NumberFormat</tt> appropriate 
for the given <tt CLASS=literal>Locale</tt> that formats 
normal numbers. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses number values in the given 
locale. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.214">getPercentInstance</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.246">public static final NumberFormat getPercentInstance()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>NumberFormat</tt> appropriate 
for the default <tt CLASS=literal>Locale</tt> that 
formats percentage values. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses percent values in the default 
locale. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.247">public static NumberFormat getPercentInstance(Locale inLocale)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>inLocale</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Locale</tt> to use. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>NumberFormat</tt> appropriate 
for the given <tt CLASS=literal>Locale</tt> that formats 
percentage values. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a <tt CLASS=literal>NumberFormat</tt> 
that formats and parses percent values in the given 
locale. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.104">Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.215">clone</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.248">public Object clone()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A copy of this <tt CLASS=literal>NumberFormat</tt>. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.clone()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a copy of this <tt CLASS=literal>NumberFormat</tt> 
and returns it. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.216">equals</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.249">public boolean equals(Object obj)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>obj</tt><br>
<DD>

<P CLASS=para>
The object to be compared with this object. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>true</tt> if the objects are equal; 
<tt CLASS=literal>false</tt> if they are not. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Object.equals()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns <tt CLASS=literal>true</tt> if 
<tt CLASS=literal>obj</tt> is an instance of <tt CLASS=literal>NumberFormat</tt> 
and is equivalent to this <tt CLASS=literal>NumberFormat</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.217">format</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.250">public final String format(double number)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>number</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>double</tt> value to be formatted. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A string that contains a formatted representation of the value. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given number and returns the result as a string. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.251">public final String format(long number)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>number</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>long</tt> value to be formatted. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A string that contains a formatted representation of the value. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given number and returns the result as a string. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.252"><DIV CLASS=screen> <P> <PRE> public final StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>number</tt><br>
<DD>

<P CLASS=para>
The object to be formatted.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>toAppendTo</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>StringBuffer</tt> 
on which to append the formatted information.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>pos</tt><br>
<DD>

<P CLASS=para>
A number field. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The given buffer <tt CLASS=literal>toAppendTo</tt> 
with the formatted representation of the object appended to it. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.format(Object, 
StringBuffer, FieldPosition)</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given object and appends the result to the given 
<tt CLASS=literal>StringBuffer</tt>. If <tt CLASS=literal>pos</tt> 
refers to one of the number fields, its beginning and ending indices are 
filled with the beginning and ending positions of the given field in the 
resulting formatted string. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.253"><DIV CLASS=screen> <P> <PRE> public abstract StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>number</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>double</tt> 
value to be formatted.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>toAppendTo</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>StringBuffer</tt> 
on which to append the formatted information.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>pos</tt><br>
<DD>

<P CLASS=para>
A number field. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The given buffer <tt CLASS=literal>toAppendTo</tt> 
with the formatted representation of the object appended to it. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given number and appends the result to the given 
<tt CLASS=literal>StringBuffer</tt>. If <tt CLASS=literal>pos</tt> 
refers to one of the number fields, its beginning and ending indices are 
filled with the beginning and ending positions of the given field in the 
resulting formatted string. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.254"><DIV CLASS=screen> <P> <PRE> public abstract StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>number</tt><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>long</tt> 
value to be formatted.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>toAppendTo</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>StringBuffer</tt> 
on which to append the formatted information.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>pos</tt><br>
<DD>

<P CLASS=para>
A number field. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The given buffer <tt CLASS=literal>toAppendTo</tt> 
with the formatted representation of the object appended to it. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given number and appends the result to the given 
<tt CLASS=literal>StringBuffer</tt>. If <tt CLASS=literal>pos</tt> 
refers to one of the number fields, its beginning and ending indices are 
filled with the beginning and ending positions of the given field in the 
resulting formatted string. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.218">getMaximumFractionDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.255">public int getMaximumFractionDigits()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The maximum number of digits allowed in the fraction 
portion. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the maximum number of digits that can be in the fraction 
part of the number. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.219">getMaximumIntegerDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.256">public int getMaximumIntegerDigits()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The maximum number of digits allowed in the integer 
portion. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the maximum number of digits that can be in the integer 
part of the number. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.220">getMinimumFractionDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.257">public int getMinimumFractionDigits()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The minimum number of digits allowed in the fraction 
portion. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the minimum number of digits that can be in the fraction 
part of the number. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.221">getMinimumIntegerDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.258">public int getMinimumIntegerDigits()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The minimum number of digits allowed in the integer 
portion. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the minimum number of digits that can be in the integer 
part of the number. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.222">hashCode</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.259">public int hashCode()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A hashcode for this object. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Object.hashCode()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns a hashcode for this <tt CLASS=literal>NumberFormat</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.223">isGroupingUsed</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.260">public boolean isGroupingUsed()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>boolean</tt> value that indicates 
whether or not this <tt CLASS=literal>NumberFormat</tt> 
uses a grouping character to break up long sequences of digits in the integer 
part of a number. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns <tt CLASS=literal>true</tt> if 
this <tt CLASS=literal>NumberFormat</tt> uses a grouping 
character. For example, it is common in the United States to use a comma 
as a grouping character: <tt CLASS=literal>1,234.56</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.224">isParseIntegerOnly</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.261">public boolean isParseIntegerOnly()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>boolean</tt> value that indicates 
whether or not this <tt CLASS=literal>NumberFormat</tt> 
parses only integers. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns <tt CLASS=literal>true</tt> if 
this <tt CLASS=literal>NumberFormat</tt> parses only 
integers. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.225">parse</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.262">public Number parse(String text) throws ParseException</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>text</tt><br>
<DD>

<P CLASS=para>
The string to be parsed.</DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Number</tt> object represented 
by the given string. 

<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>ParseException</tt><br>
<DD>

<P CLASS=para>
If the text cannot be parsed as a number. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method parses a number from the given string, starting from the beginning 
of the string. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.263"><DIV CLASS=screen> <P> <PRE> public abstract Number parse(String text, ParsePosition parsePosition) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>text</tt><br>
<DD>

<P CLASS=para>
The string to be parsed.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>parsePosition</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>ParsePosition</tt> 
object that specifies a position in the string. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Number</tt> object represented 
by the text starting at the given position. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method parses a number from the given string, starting from the given 
position. After the string has been parsed, the given <tt CLASS=literal>ParsePosition</tt> 
object is updated so that its index is after the parsed text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.226">parseObject</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.264"><DIV CLASS=screen> <P> <PRE> public final Object parseObject(String source, ParsePosition parsePosition) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>source</tt><br>
<DD>

<P CLASS=para>
The string to be parsed.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>parsePosition</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>ParsePosition</tt> 
object that specifies a position in the string. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The object represented by the text starting at the given position. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.parseObject(String, 
ParsePosition)</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method parses a number from the given string, starting from the given 
position. After the string has been parsed, the given <tt CLASS=literal>ParsePosition</tt> 
object is updated so that its index is after the parsed text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.227">setGroupingUsed</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.265">public void setGroupingUsed(boolean newValue)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>newValue</tt><br>
<DD>

<P CLASS=para>
The new grouping flag. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets whether or not this <tt CLASS=literal>NumberFormat</tt> 
uses a grouping character to break up long sequences of digits in the integer 
part of a number. For example, it is common in the United States to use 
a comma as a grouping character: <tt CLASS=literal>1,234.56</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.228">setMaximumFractionDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.266">public void setMaximumFractionDigits(int newValue)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>newValue</tt><br>
<DD>

<P CLASS=para>
The new maximum number of fraction digits. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the maximum number of digits that may be present 
in the fraction part of the number. The maximum value must be greater than 
the minimum number of fraction digits allowed. If the value is less than 
the current minimum, the minimum is also set to this value. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.229">setMaximumIntegerDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.267">public void setMaximumIntegerDigits(int newValue)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>newValue</tt><br>
<DD>

<P CLASS=para>
The new maximum number of integer digits. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the maximum number of digits that may be present 
in the integer part of the number. The maximum value must be greater than 
the minimum number of integer digits allowed. If the value is less than 
the current minimum, the minimum is also set to this value. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.230">setMinimumFractionDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.268">public void setMinimumFractionDigits(int newValue)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>newValue</tt><br>
<DD>

<P CLASS=para>
The new minimum number of fraction digits. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the minimum number of digits that may be present 
in the fraction part of the number. The minimum value must be less than 
the maximum number of fraction digits allowed. If the value is greater 
than the current maximum, the maximum is also set to this value. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.231">setMinimumIntegerDigits</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.269">public void setMinimumIntegerDigits(int newValue)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>newValue</tt><br>
<DD>

<P CLASS=para>
The new minimum number of integer digits. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the minimum number of digits that may be present 
in the integer part of the number. The minimum value must be less than 
the maximum number of integer digits allowed. If the value is greater than 
the current maximum, the maximum is also set to this value. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.232">setParseIntegerOnly</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.270">public void setParseIntegerOnly(boolean value)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>value</tt><br>
<DD>

<P CLASS=para>
The new parsing flag. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets whether or not this <tt CLASS=literal>NumberFormat</tt> 
parses only integers. If the value is <tt CLASS=literal>true</tt>, 
this <tt CLASS=literal>NumberFormat</tt> only parse 
integers. Otherwise it parses both the integer and fractional parts of 
numbers. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.105">Inherited Methods</A></h2>

<DIV CLASS=informaltable>
<P>
<TABLE CLASS=INFORMALTABLE>
<TR CLASS=row>
<TH ALIGN="LEFT">Method</TH>
<TH ALIGN="LEFT">Inherited From</TH>
<TH ALIGN="LEFT">Method</TH>
<TH ALIGN="LEFT">Inherited From</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>finalize()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>format(Object)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Format</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>getClass()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>notify()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>notifyAll()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>parseObject(String)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Format</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>toString()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait(long)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait(long, int)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
</TABLE>
<P>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.106">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>ChoiceFormat</tt>, 
<tt CLASS=literal>DecimalFormat</tt>, 
<tt CLASS=literal>FieldPosition</tt>, 
<tt CLASS=literal>Format</tt>, 
<tt CLASS=literal>Number</tt>, 
<tt CLASS=literal>ParseException</tt>, 
<tt CLASS=literal>ParsePosition</tt>, 
<tt CLASS=literal>String</tt>, 
<tt CLASS=literal>StringBuffer</tt> 
</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch16_13.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch16_15.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>MessageFormat</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>ParseException</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
